<?php
	//@GEOMAP INTERSECTION.
	$filterUrls = array();
	if(isset($distanceSearch))
	{
		$filterUrls[__('Distance')] =  array('sort'=>'Listing.distance','direction'=>'asc');
	}
	$newFilterUrls = array(
		__("Featured") => array('sort'=>'Listing.is_featured','direction'=>'desc'),
		__('Title')=> array('sort'=>'Listing.title','direction'=>'asc'),
		__('Most recent')=> array('sort'=>'Listing.created','direction'=>'desc'),
		__('Highest user rating')=> array('sort'=>'Listing.userAvg','direction'=>'desc'),
		__('Lowest user rating')=> array('sort'=>'Listing.userAvg','direction'=>'asc'),
		__('Most reviewed')=> array('sort'=>'Listing.review_count','direction'=>'desc'),
	);
	if(!cr('GeneralConfig.disable_editor_reviews'))
	{
		$newFilterUrls[__('Highest editorial rating')] = array('sort'=>'Listing.editorialAvg','direction'=>'desc');
		$newFilterUrls[__('Lowest editorial rating')] = array('sort'=>'Listing.editorialAvg','direction'=>'asc');
	}
	$filterUrls = am($filterUrls,$newFilterUrls);
  $getParams = $_GET;
  unset($getParams['url']);
  
	foreach($filterUrls as &$filterUrl)
	{
		$filterUrl = am(am($this->params['named'],$this->params['pass']),$filterUrl);
		$filterUrl['page'] = null;
    if($getParams)
    {
        $filterUrl['?'] = $getParams;
    }
		$filterUrl = $appHtml->url($filterUrl);			
	}
	$pagingUrl = $this->getPagingUrl();
	$presentUrl = $appHtml->url(am($pagingUrl,array_diff_key($this->params['named'],array("page"=>null)),array('?'=>$getParams)));
  if(!isset($this->params['named']['sort']))
	{
		$presentUrl = $html->url($filterUrls[__('Featured')]);
	}else if($this->params['isAjax']=='')
	{
		//$presentUrl = $appHtml->url($presentUrl.'/sort:Listing.created/direction:desc');
	}	
	$filterUrls = array_flip($filterUrls);	
	$paginator->options(array('url'=>$this->getPagingUrl()));
?>
<div class="index_filter">
<?php 
	echo $form->input('listing_filter',array('label'=>__('Sort By'),'type'=>'select','options'=>$filterUrls,'onchange'=>"$('#sortLink').attr('href',$(this).val()).trigger('click')",'value'=>$presentUrl));
?>

<a style = 'display: none;' id="sortLink" class="paging_ajaxify"></a>
</div>
<div class="clear"></div>